class ViewAdvertismentController < ApplicationController

  layout"fulladvertisment"

  def show
    @advertisment = Advertisment.find(:first , :conditions => { :id => params[:id]})
#    @advertisment = Advertisment.find(:first , :conditions => { :id => "31731"})

    @university=@advertisment.university
    @username = User.find(:all, :conditions => { :id => @advertisment.user_id})
    @similarads = Advertisment.find(:all, :conditions => { :sub_category_id => @advertisment.sub_category_id},:limit=>'3')
#    @advertismentattributes = AdvertismentAttributeFieldValue.find(:all, :conditions => { :advertisment_id => "31731"})
    @advertismentattributes = AdvertismentAttributeFieldValue.find(:all, :conditions => { :advertisment_id => @advertisment.id})
    @images = Attachment.find(:all, :conditions => { :advertisment_id => @advertisment.id})
    @firstimage = Attachment.find(:first, :conditions => { :advertisment_id => @advertisment.id})
    @imagescount = Attachment.count(:all, :conditions => { :advertisment_id => @advertisment.id})
    
  end

  def reply
     if request.post?
     @query = Query.new(:advertisment_id=>params[:id],:person_email=>params[:query][:email],:person_number=>params[:query][:mobile],:content=>params[:query][:content])

     @query.save
      end
#  redirect_to :action =>"show"
  end
  def swapimage

        @advertisment = Advertisment.find(:first , :conditions => { :id => params[:id]})
#    @advertisment = Advertisment.find(:first , :conditions => { :id => "31731"})

    @university=@advertisment.university
    @username = User.find(:all, :conditions => { :id => @advertisment.user_id})
    @similarads = Advertisment.find(:all, :conditions => { :sub_category_id => @advertisment.sub_category_id},:limit=>'3')
#    @advertismentattributes = AdvertismentAttributeFieldValue.find(:all, :conditions => { :advertisment_id => "31731"})
    @advertismentattributes = AdvertismentAttributeFieldValue.find(:all, :conditions => { :advertisment_id => @advertisment.id})
    @images = Attachment.find(:all, :conditions => { :advertisment_id => @advertisment.id})
    
    @imagescount = Attachment.count(:all, :conditions => { :advertisment_id => @advertisment.id})
    @firstimage = Attachment.find(:first, :conditions => { :id => params[:imageid]})
     render :layout => false 
  end

  def fullimage

     @advertisment = Advertisment.find(:first , :conditions => { :id => params[:id]})
#    @advertisment = Advertisment.find(:first , :conditions => { :id => "31731"})

    @university=@advertisment.university
    @username = User.find(:all, :conditions => { :id => @advertisment.user_id})
    @similarads = Advertisment.find(:all, :conditions => { :sub_category_id => @advertisment.sub_category_id},:limit=>'3')
#    @advertismentattributes = AdvertismentAttributeFieldValue.find(:all, :conditions => { :advertisment_id => "31731"})
    @advertismentattributes = AdvertismentAttributeFieldValue.find(:all, :conditions => { :advertisment_id => @advertisment.id})
    @images = Attachment.find(:all, :conditions => { :advertisment_id => @advertisment.id})

    @imagescount = Attachment.count(:all, :conditions => { :advertisment_id => @advertisment.id})
    @firstimage = Attachment.find(:first, :conditions => { :id => params[:imageid]})
     render :layout => false
  end
end
